'''
Created on May 10, 2010

@author: dkadish
'''
import sprites
import networkx as nx
import uuid

class Idea():
    def __init__(self, layout, position, text=''):
        self.uuid = uuid.uuid4()
        self.text = text
        self.layout = layout
        self.sprite = sprites.IdeaSprite(self, position)
        
    def __str__(self):
        return str(self.uuid)
    
    @property
    def position(self):
        try:
            return self.layout.nodes[self]
        except KeyError:
            self.layout.do_layout()
            return self.layout.nodes[self]

class Link():
    def __init__(self, ideas):
        self.ideas = ideas
        self.sprite = sprites.LinkSprite(self)
        
class Layout(nx.Graph):
    
    def __init__(self):
        nx.Graph.__init__(self)
        self.nodes = {}
    
    def do_layout(self):
        self.nodes = nx.graphviz_layout(self)